$(document).ready(function(){
	$("#pageFormContent2_air").hide();
	
	$("#seachChannelBtn_air").click(function(){
		asyncbox.open({
			url : "pricemanager/Price/supplierFindAirliftChannel.jsp",
			width : 650,
			height : 450,
			top : 65,
			drag : false,
			modal : true,
			scrolling : "yes",
			title : "国际空运渠道信息",
			tipsbar : {
				title : '国际空运渠道信息查询',
				content : '国际空运渠道信息查询'
			},
			btnsbar : $.btn.OKCANCEL,
			callback : function(action,iframe,returnValue){
				if(action == 'ok'){
					var strs = returnValue.split("|:,:|");
					$("#channelName_air").attr("value",strs[1]);
					$("#channelNum_air").attr("value",strs[0]);
				}else{
					
				}
			}
		});
	});
//------------------------------------------------------
	$("input[name='swatch']").each(function(){
		this.onclick = function(){
			switch(this.id){
				case "swatch1":
					$("#weight_air").attr("value","0-45,45-100,100-300,300-500,500-1000,1000-9999");
					break;
				case "swatch2":
					$("#weight_air").attr("value","45-100,100-300,300-500,500-1000,1000-9999");
					break;
				case "swatch3":
					$("#weight_air").attr("value","45-100,100-500,500-1000,1000-9999");
					break;
				case "swatch4":
					$("#weight_air").attr("value","0-45,45-100,100-500,500-9999");
					break;
			}
		}
	});
	
	$("#theNextBtn_air_i").click(function(){
		if($("#channelNum_air").val() == ""){
			alertMsg.error("请选择渠道");
			return;
		}
		if($("input[name='airliftPrice.PPartitionNumber']").val() == ""){
			alertMsg.error("输入空运价格名称");
			return;
		}
		if($("#priceStartDate_air").val() ==""){
			alertMsg.error("请选择生效日期");
			return;
		}
		if($("#priceEndDate_air").val() ==""){
			alertMsg.error("请选择结束日期");
			return;
		}
		if($("#priceEndDate_air").val() <= $("#priceStartDate_air").val()){
			alertMsg.error("请正确选择结束日期");
			return;
		}
		if(isNaN($("#otherFare_air").val())){
			alertMsg.error("请正确填写费用");
			return;
		}
		if($("#weight_air").val() == ""){
			alertMsg.error("请填写重量段");
			return;
		}
		
		var weightList = $("#weight_air").val().split(",");
		var weights;
		for(var i in weightList){
			weights = weightList[i].split("-");
			if(weights.length != 2 || isNaN(weights[0]) || isNaN(weights[1])){
				alertMsg.error("请正确填写重量段");
				return;
			}
		}
		//价格名称验证
		$.post("../checkPriceNameJson!checkPriceName.action",{"channelNum":$("#channelNum_air").val(),"clientOrTypeNum":$("input[name='airliftPrice.classNumber']").val(),"priceName":$("input[name='airliftPrice.PPartitionNumber']").val()},function(exist){
			if(exist){
				alertMsg.error("空运价格有重复,请重新输入");
				return;
			}else{
				$("#channelName_air_sub").attr("value",$("#channelName_air").val());
				var trRow = document.getElementById("remark_air");
				//insertCell(0);
				var strs = $("#weight_air").val().split(",");
				var weightTd;
				for(var i = 0; i < strs.length; i++){
					weightTd = trRow.insertCell(i+2);
					weightTd.style.width = 60;
		//			weightTd.style.height = 20;
		//			weightTd.style.lineHeight = 20;
					weightTd.innerHTML = strs[i];
				}
				$("#pricesContext_air").attr("colspan",strs.length+5);
				$("#pageFormContent1_air").fadeOut("normal");
				$("#pageFormContent2_air").show("slow");
			}
		});
	});
	$("#theBackBtn_air").click(function(){
		var trRow = document.getElementById("remark_air");
		while(trRow.getElementsByTagName("td").length>5){
			trRow.deleteCell(2);
		}
		$("#pageFormContent2_air").fadeOut("normal");
		$("#pageFormContent1_air").show("slow");
	});
	
});